<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_STATISTICS_MNG;

require "../framepages/moudle_base.php";


$productor_id = $_GET['productor_id'];
$date = $_GET['date'];
$productor_record = \Data\Tree_productor_DAO::getRecord($productor_id);
$species_id = $productor_record->getSPECIES_ID();
$species_record = \Data\Tree_species_DAO::getRecord($species_id);
$species_name = $species_record->getSPECIES_NAME();
$dw = $species_record->getDW();

$gg_id = $productor_record->getGG_ID();
$gg_record = \Data\Tree_gg_DAO::getRecord($gg_id);
$gg_name = $gg_record->getGG_NAME();
$gg_dw = $gg_record->getGG_DW();
$gg_full_name = $gg_name."($gg_dw)";

$gg_cs = $productor_record->getGG_CS();
$province = $productor_record->getPROVINCE();
$city = $productor_record->getCITY();
$county = $productor_record->getCOUNTY();
$price = $productor_record->getPRICE();
$visit_count = $productor_record->getVISIT_COUNT();

?>
<div class="main-content">
    <div>
        <table>
            <tr>
                <th width="8%">品种名称：</th>
                <td width="10%"><?php echo $species_name ?></td>
                <th width="8%">规格类型：</th>
                <td width="12%"><?php echo $gg_full_name ?></td>
                <th width="8%">规格参数：</th>
                <td width="5%"><?php echo $gg_cs ?></td>
                <th width="5%">单位：</th>
                <td width="5%"><?php echo $dw ?></td>
                <th>地区：</th>
                <td><?php echo $province."--".$city."--".$county ?></td>
                <th width="6%">询价次数:</th>
                <td width="5%"><?php echo $visit_count ?></td>
                <th>日期</th>
                <td><?php echo  $date ?></td>
            </tr>
        </table>
    </div>

    <div>
        <div>
            <span><h2>询价记录</h2></span>
        </div>
        <div>
            <table class="table" style="word-break:break-all">
                <tr>
                    <th width="9%">序号</th>
                    <th width="9%">手机号</th>
                    <th width="9%">询价时间</th>
                </tr>

            <?php
            $page_index = $_GET['page_index'];
            if (!$page_index) {
                $page_index = 1;
            }
            $every_page_counts = 30;
            $list_start = ($page_index-1)*$every_page_counts;

            $customer_action_log_list_array = \Data\Tree_customer_action_log_DAO::getListByProductorId($productor_id,$date,$list_start,$every_page_counts);
            $customer_action_log_list = $customer_action_log_list_array[1];
            $total_count = $customer_action_log_list_array[0];
            $page_count = ceil($total_count/$every_page_counts);
            $page_last = $page_index-1;
            $page_next = $page_index+1;
            $i = $list_start+1;
                foreach ($customer_action_log_list as $customer_action_log_record) {
                    $customer_id = $customer_action_log_record->getCUSTOMER_ID();
                    $created_on = $customer_action_log_record->getCREATED_ON();
                    $customer_record = \Data\Tree_customer_info_DAO::getRecord($customer_id);
                    //$customer_name = $customer_record->getCUSTOMER_NAME();

                    $phone_number = $customer_record->getPHONE_NUMBER();

                    echo "
                        <tr>
                            <td>$i</td>
                            <td>$phone_number</td>
                            <td>$created_on</td>                        
                        </tr>                   
                    
                    ";
                    $i++;
                }
            ?>
            </table>
        </div>
        <div style="margin-left:35%; margin-top:40px;">
            <div>
                <?php
                if ($page_last) {
                    echo "            
                    <button onclick='last_page($page_last)'>上一页</button>                            
                ";
                }

                if ($page_next<=$page_count) {
                    echo "         
                    <button onclick='next_page($page_next)'>下一页</button>               
                ";
                }

                if ($page_count>1) {
                    echo "
                    &nbsp;&nbsp;&nbsp;&nbsp;去往第<input type='text' name='go_page' id='go_page' size='3'>页
                <button onclick='go_page()'>GO</button>
                    ";
                }
                ?>



            </div>

            <div style="margin-left:5%; margin-top:20px;">
                第<?php echo $page_index ?>页 &nbsp;&nbsp;&nbsp;&nbsp;
                共<?php echo $page_count ?>页  &nbsp;&nbsp;&nbsp;&nbsp;共<?php echo $total_count ?>条记录
            </div>


        </div>

    </div>


</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>

<script>
    function last_page(page_last) {
        needle = $('#4sStoreName').val();
        url = "?page_index="+page_last+"&needle"+needle+"&date="+"<?php echo $date ?>";
        window.location.href = url;
    }

    function next_page(page_next) {
        needle = $('#4sStoreName').val();
        url = "?page_index="+page_next+"&needle"+needle+"&date="+"<?php echo $date ?>";
        window.location.href = url;
    }

    function go_page()
    {
        needle = $('#4sStoreName').val();
        url = "?page_index="+$('#go_page').val()+"&needle"+needle+"&date="+"<?php echo $date ?>";
        window.location.href = url;
    }
</script>
</body>
</html>
